package net.tycmc.cty.ctyms.timejob.iems.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;

public class WeatherCatchDAO {
	
	private IBaseDAO baseDAO;
	
	private ITransactionDAO tranDAO;

	/**
	 * @return the baseDAO
	 */
	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	/**
	 * @param baseDAO the baseDAO to set
	 */
	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}
	
	/**
	 * @return the tranDAO
	 */
	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}

	/**
	 * @param tranDAO the tranDAO to set
	 */
	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}

	/**
	 * 获取城市天气代码
	 */
	public List<Map<String,Object>> getWeatherCode_City(){
		String strSQL = "select * from WeatherCode_City where GETDATE() between WthCC_Eff and WthCC_Exp;";
		List<Map<String,Object>> list = baseDAO.execQuery(strSQL, new Object[]{});
		return list;
	}
	
	/**
	 * 插入城市天气捕捉到的记录信息
	 * @param list
	 * @return
	 */
	public boolean iWeatherInfo_City(List<Map<String,Object>> list,String infoDate){
		if(!StringUtil.isNullOrEmpty(infoDate))return false;
		List<String> sqlList = new ArrayList<String>();
		for(Map<String,Object> map:list){
			String sql = "insert into WeatherInfo_City (WthIC_CityName,WthIC_SourceInfo,WthIC_Temp,WthIC_Weather,WthIC_Wind,WthIC_InfoDate)" +
					"values('"+MapGetter.getString(map, "WthIC_CityName")+"'," +
							"'"+MapGetter.getString(map, "WthIC_SourceInfo")+"'," +
							"'"+MapGetter.getString(map, "WthIC_Temp")+"'," +
							"'"+MapGetter.getString(map, "WthIC_Weather")+"'," +
							"'"+MapGetter.getString(map, "WthIC_Wind")+"'," +
							"'"+infoDate+"')";
			sqlList.add(sql);
		}
		boolean retFlag = tranDAO.batch(sqlList);
		return retFlag;
	}
}
